package cn.coisini.controller.v1;

import cn.coisini.api.view.ArticleViewControllerApi;
import cn.coisini.model.common.annotation.RedisAccessLimit;
import cn.coisini.model.common.dtos.Result;
import cn.coisini.model.common.enums.ResultEnum;
import cn.coisini.model.dto.CategoryDto;
import cn.coisini.model.pojo.Article;
import cn.coisini.model.vo.QueryVo;
import cn.coisini.service.ArticleViewService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author xiangshaw
 * Description: 文章 前端接口
 */
@RestController
@RequiredArgsConstructor
public class ArticleViewController implements ArticleViewControllerApi {

    private final ArticleViewService articleViewService;
    /**
     * 查询文章列表
     */
    @Override
    @RedisAccessLimit(seconds = 60, maxCount = 30)
    public Result<Object> getArticleViewList(QueryVo queryVo) {
        return articleViewService.getArticleViewList(queryVo);
    }

    /**
     * 查询分类列表
     */
    @Override
    @RedisAccessLimit(seconds = 60, maxCount = 30)
    public Result<List<Map<String, Object>>> getCategoryViewList() {
        return articleViewService.getCategoryViewList();
    }

    /**
     * 推荐分类
     */
    @Override
    @RedisAccessLimit(seconds = 60, maxCount = 30)
    public Result<List<Map<String, Object>>> getRecommendCategoryViewList() {
        return articleViewService.getRecommendCategoryViewList();
    }

    /**
     * 添加或取消推荐分类
     */
    @Override
    @RedisAccessLimit(seconds = 60, maxCount = 30)
    public Result<ResultEnum> updateRecommendCategory(CategoryDto categoryDto) {
        return articleViewService.updateRecommendCategory(categoryDto);
    }

    /**
     * 查询文章详情
     */
    @Override
    public Result<Article> getArticleViewDetail(String id) {
        return articleViewService.getArticleViewDetail(id);
    }
}
